#ifndef CLIENTSDATABASE_H
#define CLIENTSDATABASE_H

#include <QObject>
#include <QVector>
#include <QMap>
#include <QStringList>
#include <QMessageBox>
#include <QStringList>
#include "clientthread.h"
#include "ipconnection.h"




class ClientsDataBase
{
private:
    QVector <IpConnection *> _database;
    QMutex mutex;

public:

    ~ClientsDataBase();

    int registerClientThread(ClientThread *);
    int removeClientThread(ClientThread *);
    IpConnection *at(int, bool mutex_lock = false);

    void push_back(ClientThread *cth);
    void erase(ClientThread *cth);
    int findThread(ClientThread *, bool mutex_lock = false);
    int findClientByIP(const QString & ip, bool mutex_lock = false);
    QList <IpConnection*> clients();
    QStringList clientsIpList();
    int killClientsByIpList(const QStringList & l, bool wait_for_disconnect = false, bool force = false);

    inline int size() {
        return _database.size();
    }

    void waitForEmpty();


    inline IpConnection *operator [](int i){
        return at(i);
    }

    void lock() {
        mutex.lock();
    }

    void unlock() {
        mutex.unlock();
    }
};


#endif // CLIENTSDATABASE_H
